﻿using WeatherStationSys.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeatherStationSys.Common;

namespace Nimbus2._0Platform
{
    /// <summary>
    /// Nimbus2.0硬件平台气压传感器(高成本硬件的平台)
    /// </summary>
    public class Nimbus2_0BarometricPressureSensor : AbstractBarometricPressureSensor
    {
        /// <summary>
        /// 观察者集合
        /// </summary>
        private List<IObserver> container;

        /// <summary>
        /// Ctor
        /// </summary>
        public Nimbus2_0BarometricPressureSensor()
        {
            container = new List<IObserver>();
        }

        public override double Read()
        {
            double currentBarometricPressure = 102;//假设当前大气压力

            return currentBarometricPressure;
        }

        /// <summary>
        /// 通知每1个观察者显示气压
        /// </summary>
        /// <param name="obj"></param>
        public override void NotifyObservers(double pressure)
        {
            foreach (var item in container)
            {
                ((IObserver)item).Update(pressure);
            }
        }

        /// <summary>
        /// 注册/添加观察者
        /// </summary>
        /// <param name="obj"></param>
        public override void AddObserver(IObserver obj)
        {
            container.Add(obj);
        }

        /// <summary>
        /// 移除/删除观察者
        /// </summary>
        /// <param name="obj"></param>
        public override void UnRegisterObserver(IObserver obj)
        {
            container.Remove(obj);
        }
    }
}
